package lightswitch.server.code.sqlhelper.expression.operators.relational;

import java.util.List;

import lightswitch.server.code.sqlhelper.ExpressionHelper;
import lightswitch.server.code.sqlhelper.expression.BinaryExpression;
import lightswitch.server.code.object.DataRow;
import lightswitch.server.code.sqlhelper.expression.Expression;
import lightswitch.server.code.sqlhelper.statement.select.From;
import lightswitch.server.code.util.TypeOfData;

public class EqualsTo extends BinaryExpression {
	public EqualsTo(Expression left, Expression right, boolean isNot)
	{
			this.leftExpression = left;
			this.rightExpression=right;
			this.isNot=isNot;

	}
	public EqualsTo(String left, String right, boolean isNot, From _from)
	{
				
			this.isNot=isNot;
			leftExpression = ExpressionHelper.parseExpression(left,_from);
			rightExpression = ExpressionHelper.parseExpression(right,_from);
			
	
	}
	public String toString()
	{
		if(isNot == false)
			return "("+leftExpression.toString() + " = " + rightExpression.toString() +" )";
		else
			return "("+leftExpression.toString() + " != " + rightExpression.toString() +" )";
	}
	public Object GetValue(DataRow row, List<From> parentFromList) {
		dataType = TypeOfData.BOOLEAN;
		Object left = leftExpression.GetValue(row,parentFromList);
		Object right = rightExpression.GetValue(row,parentFromList);
		if(left.toString().toLowerCase().equals(right.toString().toLowerCase()))
		{
			return true;
		}
		else
			return false;
	}

}
